<template>
  <div class="weblog-info">
    <div class="title">
      <span @click="handleEditClick(info.id)">{{ info.title }}</span>
    </div>
    <div class="createTime">
      <div class="time">
        <span>创建时间: {{ formatTime(info.createAt) }}</span>
        <span>更新时间: {{ formatTime(info.updateAt) }}</span>
      </div>
      <div class="operation">
        <span class="editor" @click="handleEditClick(info.id)">编辑</span>
        <span class="remove" @click="handleRemoveClick(info.id)">删除</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { useRouter } from "vue-router"
import { formatTime } from "../../../utils/formatTime";
// 页面数据
const router = useRouter()
const props = defineProps({
  info: {
    type: Object,
    default: {},
  },
});
const emit = defineEmits(["remove"])
// 事件处理
const handleRemoveClick = (id) => {
  emit("remove", id)
}

const handleEditClick = (id) => {
  router.push({ path: `/editarticle/${id}` })
}
</script>

<style scoped>
.weblog-info {
  display: flex;
  flex-direction: column;
  height: 100px;
  width: 100%;
  /* background-color: #CCFFFF; */
  margin: 20px 0;
  justify-content: space-around;
  border-radius: 10px;
  padding: 10px;
  box-sizing: border-box;
  border: 1px solid #666;
}

.title {
  font-size: 17px;
  margin-left: 10px;
}

.title span:hover {
  color: #fc6d59;
  cursor: pointer;
}

.createTime {
  display: flex;
  justify-content: space-between;
}

.createTime span {
  margin: 0 10px;
}

.createTime .time span {
  font-size: 12px;
  color: #888;
  user-select: none;
}

.createTime .operation span {
  font-size: 14px;
  color: #666;
  cursor: pointer;
}

.createTime .operation span:hover {
  font-weight: bold;
}
</style>
